package com.game.proxy
{
	import com.dusk.util.UtilBase;
	import com.game.data.vo.SkillVO;
	
	public class SkillProxy extends ConfigProxy
	{
		public function SkillProxy()
		{
			super();
		}
		
		private var activeSkill:Vector.<SkillVO> = new Vector.<SkillVO>();
		
		private var passiveSkill:Vector.<SkillVO> = new Vector.<SkillVO>();
		
		override public function setConfigData(config:Object):void
		{
			super.setConfigData(config);
			initData();
		}
		
		/**
		 * 根据技能Id获取技能VO
		 * @param id 技能Id
		 * @return skillVO
		 */
		public function getSkillById(id:String):SkillVO
		{
			for each (var item:SkillVO in activeSkill)
			{
				if (item.skillId == id)
				{
					return item;
				}
			}
			return null;
		}
		
		private function initData():void
		{
			var vo:SkillVO;
			var skill:Object;
			for each (skill in UtilBase.getAllValue(_config))
			{
				if(skill.skillType == "roleActive")
				{
					vo = new SkillVO();
					vo.buildFromObject(skill);
					activeSkill.push(vo);
				}
				if(skill.skillType == "rolePassive")
				{
					vo = new SkillVO();
					vo.buildFromObject(skill);
					passiveSkill.push(vo);
				}
			}
		}
		
		public function getAllSkillByRoleId(roleId:int):Vector.<SkillVO>
		{
			var vec:Vector.<SkillVO> = new Vector.<SkillVO>();
			for each (var item:SkillVO in activeSkill)
			{
				if (item.ownerId == ("role" + roleId.toString()))
				{
					vec.push(item);
				}
			}
			return vec;
		}
		
		public function getSkillMpCostBySkillId(skillId:String,level:int):int
		{
			return getSkillById(skillId).mpCost[(level - 1)];
		}
		
		public function getSkillHurtBySkillId(skillId:String, level:int):Number
		{
			return getSkillById(skillId).skillHurt[(level - 1)];
		}
		
		/**
		 * 获取角色技能组内指定序号的技能
		 * @param roleId 角色Id，范围1-5
		 * @param belongGroup 所属组（心法），范围1-2
		 * @param index 序号，范围1-5
		 * @return
		 */
		public function getRoleSkillInGroupByIndex(roleId:int, belongGroup:int, index:int):SkillVO
		{
			for each (var item:SkillVO in activeSkill)
			{
				if (item.ownerId == ("role" + roleId.toString()) && item.belongGroup == belongGroup && item.groupIndex == index)
				{
					return item;
				}
			}
			return null;
		}
		
		/**
		 * 获取被动技能的VO
		 * @param idx 取值为1-5
		 * @return
		 */
		public function getPassiveSkillByIndex(idx:int):SkillVO
		{
			for each(var skill:SkillVO in passiveSkill)
			{
				if(idx == skill.groupIndex)
				{
					return skill;
				}
			}
			return null;
		}
	}
}
